package org.tea.application.configuration;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author lxh
 */
@Configuration
public class ThreadPoolExecutorConfig {

    @Bean("subscribeExecutor")
    public ThreadPoolExecutor crawlThreadPoolExecutor() {
        return new ThreadPoolExecutor(
                0, Integer.MAX_VALUE, 60, TimeUnit.SECONDS,
                new SynchronousQueue<>(),
                new ThreadFactoryBuilder().setNameFormat("subscribeExecutor-%d").build(),
                new ThreadPoolExecutor.AbortPolicy()
        );
    }
}
